//
//  info_proc.c
//  electronic_scale
//
//  Created by fukai on 2019/4.
//  Copyright © 2019 Cyber SmartCar Lab. All rights reserved.
//

#include "./info_proc.h"


ScaleInfoNode ScaleInfo = 
{
	.default_data = 0,
	.proc_data = 0,
	.peeled_data = 8424000,
	.weight = 0.0f,
	.unit_price = 5.0f,
	.total_price = 0.0f,
	.warning_weight = 500.0f,
};

PeeledStatusType PeeledStatus = PEELED_OFF;
WarningStatusType WarningStatus = NORMAL;

//数据处理
void ProcData(void)
{
	//重量处理
	if(PeeledStatus == PEELED_ON)
	{
		ScaleInfo.peeled_data = ScaleInfo.default_data;
	}
	ScaleInfo.proc_data = ScaleInfo.default_data - ScaleInfo.peeled_data;
	ScaleInfo.weight = (float)(ScaleInfo.proc_data/100.0) * 0.04725f;
	if(ScaleInfo.weight > -0.1 && ScaleInfo.weight < 0.1)
	{
		ScaleInfo.weight = 0;
	}
	
	//价格处理
	ScaleInfo.total_price = ScaleInfo.unit_price * (ScaleInfo.weight / 500.0);
	
	//报警状态
	if(ScaleInfo.weight >= ScaleInfo.warning_weight)
	{
		WarningStatus = WARNING;
	}
	else
	{
		WarningStatus = NORMAL;
	}
}


